<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ page import="java.sql.*" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'logincheck.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	

  </head>
  
  <body>
    This is my JSP page. <br>
    <% 
       String name=new String(request.getParameter("name"));
       String password=new String(request.getParameter("password"));
       Connection con=null;
       Statement st=null;
       ResultSet rs=null;
       if(name.equals("")){
       		response.sendRedirect("login.jsp");
       		}
       try{
       		Class.forName("com.mysql.jdbc.Driver");
       		String url="jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8";
       		con=DriverManager.getConnection(url, "root", "");
       		st=con.createStatement();
       		String sql="select * from user where name='"+name+"'";
       		rs=st.executeQuery(sql);
       		if(rs.next()){
       			String sql2="select * from user where password='"+password+"'";
       			rs=st.executeQuery(sql2);
       			if(rs.next()){
       				response.sendRedirect("index.jsp");
       			}else{
       				response.sendRedirect("login.jsp");
       			}
       		}
     }catch(Exception e){
     	e.printStackTrace();
     }finally{
     	rs.close();
     	st.close();
     	con.close();
     }
      %>
  </body>
</html>
